package best.driver.android;

import android.graphics.Bitmap;
import android.text.TextUtils;
import best.driver.android.Beans.*;
import best.driver.android.Model.OrderDetailModel;
import best.driver.android.Utils.ImageLoaderUtil;
import best.driver.android.Utils.Logger;
import best.driver.android.Utils.MD5;
import best.driver.android.common.network.*;

import java.util.Hashtable;

public class RequestFactory extends BaseRequestFactory {

	/**
	 * 用户模块
	 */
	// 验证码1
	public static ApiStringRequest creatPreloginRequest(String phoneNumber, boolean shipper) {
		Hashtable<String, Object> params = new Hashtable<String, Object>();
		params.put("phoneNumber", phoneNumber);
		if(shipper) {
			params.put("shipper", "true");
		} else {
			params.put("shipper", "false");
		}
		ApiStringRequest request = new ApiStringRequest(ApiRequest.Method.POST);
		configRequest(request, "v1/security-code/get", params);
		return request;
	}


	// 登录2
	public static ApiObjectRequest<LoginInfo> createLoginRequest(String cityId, String phoneNumber, String securityCode) {
		Hashtable<String, Object> params = new Hashtable<String, Object>();
		params.put("cityId", cityId);
		params.put("phoneNumber", phoneNumber);
		params.put("securityCode", securityCode);
		ApiObjectRequest<LoginInfo> request = new ApiObjectRequest<LoginInfo>(LoginInfo.class, ApiRequest.Method.POST);
		configRequest(request, "v1/driver/login", params);
		return request;
	}

	//版本检测
	public static ApiObjectRequest<AppVersionInfo> createGetVersionRequest(String version, boolean isShipper, String platform) {

		Hashtable<String, Object> params = new Hashtable<String, Object>();
		params.put("version", version);
		params.put("isShipper", isShipper);
		params.put("platform", platform);
		ApiObjectRequest<AppVersionInfo> request = new ApiObjectRequest<AppVersionInfo>(AppVersionInfo.class, ApiRequest.Method.POST);
		configRequest(request, "v1/version/queryNewVersion", params);
		return request;
	}


	// 提交审核
	public static ApiStringRequest createSubmitToCheckRequest(String driverId, String cityId, String name, String vehicleId,
															String truckName, String truckNum, String identityCard, String identityFrontPhoto,
															String identityBackPhoto, String truckPhoto, String driverLicensePhoto,
															String truckLicensePhoto, String operationLicensePhoto) {
		Hashtable<String, Object> params = new Hashtable<String, Object>();
		//params.put("driverId", driverId);
        params.put("cityId", cityId);
		params.put("name", name);
		params.put("vehicleId", vehicleId);
		params.put("truckName", truckName);
		params.put("truckNum", truckNum);
        params.put("identityCard", identityCard);
		params.put("identityFrontPhoto", identityFrontPhoto);
		params.put("identityBackPhoto", identityBackPhoto);
		params.put("truckPhoto", truckPhoto);
		params.put("driverLicensePhoto", driverLicensePhoto);
		params.put("truckLicensePhoto", truckLicensePhoto);
		if(!TextUtils.isEmpty(operationLicensePhoto)) {
			params.put("operationLicensePhoto", operationLicensePhoto);
		}
		ApiStringRequest request = new ApiStringRequest(ApiRequest.Method.POST);
		configRequest(request, "v1/driver/register", params);
		return request;
	}

    //查看司机审核状态
    public static ApiObjectRequest<CheckStatus> createGetCheckStatus() {
        Hashtable<String, Object> params = new Hashtable<String, Object>();
        ApiObjectRequest<CheckStatus> request = new ApiObjectRequest<CheckStatus>(CheckStatus.class, ApiRequest.Method.POST);
        configRequest(request, "v1/driver/queryAuditStatus", params);
        return request;
    }

    //查看司机详情
    public static ApiObjectRequest<DriverDetail> createGetDriverDetail() {
        Hashtable<String, Object> params = new Hashtable<String, Object>();
        ApiObjectRequest<DriverDetail> request = new ApiObjectRequest<DriverDetail>(DriverDetail.class, ApiRequest.Method.POST);
        configRequest(request, "v1/driver/detail", params);
        return request;
    }
	//开始工作
	public static ApiStringRequest createStartWorkRequest() {
		Hashtable<String, Object> params = new Hashtable<String, Object>();
		ApiStringRequest request = new ApiStringRequest(ApiRequest.Method.POST);
		configRequest(request, "v1/driver/startWork", params);
		return request;
	}

	//下班
	public static ApiStringRequest createOffWorkRequest() {
		Hashtable<String, Object> params = new Hashtable<String, Object>();
		ApiStringRequest request = new ApiStringRequest(ApiRequest.Method.POST);
		configRequest(request, "v1/driver/getOffWork", params);
		return request;
	}

	//订单流程

	//获取新订单信息
	public static ApiObjectRequest<NewOrderInfo> createGetNewOrderInfoRequest(String orderId, String location) {
		Hashtable<String, Object> params = new Hashtable<String, Object>();
		params.put("orderId", orderId);
		params.put("location", location);
		//params.put("currentLatitude", currentLatitude);
		ApiObjectRequest<NewOrderInfo> request = new ApiObjectRequest<NewOrderInfo>(NewOrderInfo.class, ApiRequest.Method.POST);
		configRequest(request, "v1/driver/newOrder", params);
		return request;
	}

	//获取订单详情
	public static ApiObjectRequest<OrderDetailInfo> createGetOrderDetailInfoRequest(String orderId) {
		Hashtable<String, Object> params = new Hashtable<String, Object>();
		params.put("orderId", orderId);
		ApiObjectRequest<OrderDetailInfo> request = new ApiObjectRequest<OrderDetailInfo>(OrderDetailInfo.class, ApiRequest.Method.POST);
		configRequest(request, "v1/driver/orderDetail", params);
		return request;
	}

	//抢单
	public static ApiStringRequest createReceiveOrderRequest(String orderId, String distance) {
		Hashtable<String, Object> params = new Hashtable<String, Object>();
		params.put("orderId", orderId);
		params.put("distance", distance);
		ApiStringRequest request = new ApiStringRequest(ApiRequest.Method.POST);
		configRequest(request, "v1/driver/chooseOrder", params);
		return request;
	}

	//司机出发
	public static ApiObjectRequest<OrderOperationPair> createStartupRequest(String orderId, String location) {
		Hashtable<String, Object> params = new Hashtable<String, Object>();
		params.put("location", location);
		params.put("orderId", orderId);
		ApiObjectRequest<OrderOperationPair> request = new ApiObjectRequest<OrderOperationPair>(OrderOperationPair.class, ApiRequest.Method.POST);
		configRequest(request, "v1/driver/startup", params);
		return request;
	}

    //开始装货
    public static ApiObjectRequest<OrderOperationPair> createLoadingRequest(String orderId, String location) {
        Hashtable<String, Object> params = new Hashtable<String, Object>();
        params.put("orderId", orderId);
		params.put("location", location);
        ApiObjectRequest<OrderOperationPair> request = new ApiObjectRequest<OrderOperationPair>(OrderOperationPair.class, ApiRequest.Method.POST);
        configRequest(request, "v1/driver/load", params);
        return request;
    }

    //开始运货
    public static ApiObjectRequest<OrderOperationPair> createTransitRequest(String orderId, String fileIds, String location) {
        Hashtable<String, Object> params = new Hashtable<String, Object>();
        params.put("orderId", orderId);
		if(!TextUtils.isEmpty(fileIds)) {
			params.put("fileIds", fileIds);
		}
        params.put("location", location);
        ApiObjectRequest<OrderOperationPair> request = new ApiObjectRequest<OrderOperationPair>(OrderOperationPair.class, ApiRequest.Method.POST);
        configRequest(request, "v1/driver/transit", params);
        return request;
    }

	//司机卸货
	public static ApiObjectRequest<OrderOperationPair> createUnloadingRequest(String orderId, String location) {
		Hashtable<String, Object> params = new Hashtable<String, Object>();
		params.put("orderId", orderId);
//		params.put("fileIds", fileIds);
		params.put("location", location);
		ApiObjectRequest<OrderOperationPair> request = new ApiObjectRequest<OrderOperationPair>(OrderOperationPair.class, ApiRequest.Method.POST);
		configRequest(request, "v1/driver/unload", params);
		return request;
	}

    //回单
    public static ApiObjectRequest<OrderOperationPair> createReturnBackRequest(String orderId, String fileIds, String location, int distance, int waitTime) {
        Hashtable<String, Object> params = new Hashtable<String, Object>();
        Logger.d("distance_return_tail", distance + "米");
        params.put("orderId", orderId);
		if(!TextUtils.isEmpty(fileIds)) {
			params.put("fileIds", fileIds);
		}
        params.put("location", location);
		params.put("waitTime", waitTime);
		params.put("distance", distance);
        ApiObjectRequest<OrderOperationPair> request = new ApiObjectRequest<OrderOperationPair>(OrderOperationPair.class, ApiRequest.Method.POST);
        configRequest(request, "v1/driver/back", params);
        return request;
    }

	//订单完成
    public static ApiObjectRequest<OrderOperationPair> createCompleteOrder(String orderId, String fileIds, String location, int distance, int waitTime) {
        Hashtable<String, Object> params = new Hashtable<String, Object>();
        Logger.d("distance_complete", distance + "米");
        params.put("orderId", orderId);
		if(!TextUtils.isEmpty(location)) {
			params.put("location", location);
		}
        params.put("fileIds", fileIds);
		params.put("waitTime", waitTime);
		params.put("distance", distance);
        ApiObjectRequest<OrderOperationPair> request = new ApiObjectRequest<OrderOperationPair>(OrderOperationPair.class, ApiRequest.Method.POST);
        configRequest(request, "v1/driver/finish", params);
        return request;
    }

    //获取订单列表
    public static ApiArrayRequest<OrderListItemInfo> createGetOrderList(String page, String pageSize) {
        Hashtable<String, Object> params = new Hashtable<String, Object>();
        ApiArrayRequest<OrderListItemInfo> request = new ApiArrayRequest<OrderListItemInfo>(OrderListItemInfo.class, ApiRequest.Method.POST);
        configRequest(request, "v1/driver/orderList", params);
        return request;
    }

     //不看本订单
    public static ApiStringRequest createIgnoreOrder(String orderId) {
        Hashtable<String, Object> params = new Hashtable<String, Object>();
        params.put("orderId", orderId);
        ApiStringRequest request = new ApiStringRequest(ApiRequest.Method.POST);
        configRequest(request, "v1/driver/ignoreOrder", params);
        return request;
    }

	public static ApiObjectRequest<OrderListInfo> createGetOrderListInfo(String page, String pageSize, Boolean isProcessing) {
		Hashtable<String, Object> params = new Hashtable<String, Object>();
		params.put("page", page);
		params.put("pageSize", pageSize);
		if(isProcessing != null) {
			params.put("isProcessing", isProcessing);
		}
		ApiObjectRequest<OrderListInfo> request = new ApiObjectRequest<OrderListInfo>(OrderListInfo.class, ApiRequest.Method.POST);
		configRequest(request, "v1/driver/orderList", params);
		return request;
	}


    //计算费用
    public static ApiObjectRequest<OrderFeeInfo> createGetOrderFeeRequest(String orderId, int distance, long waitTime) {
        Hashtable<String, Object> params = new Hashtable<String, Object>();
        params.put("orderId", orderId);
        params.put("distance", distance);
        params.put("waitTime", waitTime);
        ApiObjectRequest<OrderFeeInfo> request = new ApiObjectRequest<OrderFeeInfo>(OrderFeeInfo.class, ApiRequest.Method.POST);
        configRequest(request, "v1/driver/calculateFee", params);
        return request;
    }
	//汽车列表
	public static ApiArrayRequest<CarItemInfo> createGetCarListRequest(String cityId) {
		Hashtable<String, Object> params = new Hashtable<String, Object>();
		params.put("cityId", cityId);
		ApiArrayRequest<CarItemInfo> request = new ApiArrayRequest<CarItemInfo>(CarItemInfo.class, ApiRequest.Method.POST);
		configRequest(request, "v1/vehicle/list", params);
		return request;
	}

	//订单费用详情
	public static ApiObjectRequest<OrderFeeDetail> createGetOrderFeeDetailRequest(String orderId) {
		Hashtable<String, Object> params = new Hashtable<String, Object>();
		params.put("orderId", orderId);
		ApiObjectRequest<OrderFeeDetail> request = new ApiObjectRequest<OrderFeeDetail>(OrderFeeDetail.class, ApiRequest.Method.POST);
		configRequest(request, "v1/driver/queryOrderBill", params);
		return request;
	}




}